<?php
error_reporting( E_ALL | E_STRICT );
	include('functions.php');

	// Dynamic assign a number of authors to create
	if(isset($_GET['a'])) {
		$acount = $_GET['a'];
		$createAuthor = true;
	} else {
		//$acount = 100;
		$createAuthor = false;
	}

	// Dynamic assign a number of posts to create
	if(isset($_GET['p'])) {
		$pcount = $_GET['p'];
		$createPosts = true;
	} else {
		$createPosts = false;
	}
	
if($createAuthor) {

	echo "<h1>CREATE AUTHORS</h1><br />";
	for($i=0; $i<$acount; $i++) {	
		set_time_limit(0);
		q('authors')->insert(createAuthor($i));
	}
	echo "<h1>DONE CREATING ".$acount." AUTHORS</h1><br /><br />";
}

if($createPosts) {
	echo "<h1>CREATE POSTS</h1><br /><br />";

	$batchCount = 0;
	$posts = array();
	
	$startTotal = timeit();
	for($i=0; $i < $pcount; $i++) {
		set_time_limit(0);
		ini_set("memory_limit","500M");
		$batchCount++;
		$posts[] = Posts();
		// Ensure that we batch insert 3000 posts at the time
		// Thus feature has been added after normal inserts to measure the difference
		if($batchCount == 3000){
			$batchCount = 0;
			$start = timeit();
//			q('post')->insert(Posts());
			q('post')->batchInsert($posts);
			
			$end = timeit();
			$time = number_format($end - $start, 15);
			l($time);
			unset($posts);
		}
	}
	$endTotal = timeit();
	$timeTotal = number_format($endTotal - $startTotal, 15);
	echo "<h1>".$timeTotal . "</h1><br />";

	echo "<h1>DONE CREATING ".$pcount." POSTS</h1><br /><br />";
}
?>